package com.xxyy.mylive.ui.activity;

import android.content.Intent;
import android.graphics.Point;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.orhanobut.logger.Logger;
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.xxyy.mylive.MyApplication;
import com.xxyy.mylive.R;
import com.xxyy.mylive.http.HttpApi;
import com.xxyy.mylive.tools.UiTool;
import com.xxyy.mylive.ui.BaseActivity;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

public class LoginActivity extends BaseActivity implements View.OnClickListener {
    private JCVideoPlayerStandard videoAds;
    private TextView tvLoginWeixin;
    private Button btnLogin;

//    private IWXAPI wxApi;
    public static LoginActivity instance;

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_login);
    }

    @Override
    protected void initUI() {
        videoAds = (JCVideoPlayerStandard) findViewById(R.id.video_login_ads);
        tvLoginWeixin = (TextView) findViewById(R.id.tv_login_weixin);
        btnLogin = (Button) findViewById(R.id.btn_login);
    }

    @Override
    protected void setListener() {
        tvLoginWeixin.setOnClickListener(this);
        btnLogin.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        instance = this;
//        regToWx();
        String url = "http://v.1318.com/jcs_opening/yjh_ad.mp4";
        videoAds.setUp(url, JCVideoPlayerStandard.CURRENT_STATE_NORMAL, "广告视频");

        Point point = UiTool.getScreenPoint(this);
        int width = point.x;
        int height = point.y;
        Logger.i("屏幕高度为====="+height);
        ViewGroup.LayoutParams params = videoAds.getLayoutParams();
        params.height= height/3;
    }

    @Override
    protected void onResume() {
        super.onResume();
        //自动播放视频
        videoAds.startButton.performClick();
    }

    /**
     * 初始化微信配置
     */
    private void regToWx() {
//        final String APP_ID = getResources().getString(R.string.weixin_app_id);
//        wxApi = WXAPIFactory.createWXAPI(this, APP_ID, true);
//        Logger.i("注册微信api====" + wxApi.registerApp(APP_ID));
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_login_weixin:
                //先检查是否安装了微信
                MyApplication application = (MyApplication) getApplicationContext();
                IWXAPI wxApi = application.getWxApi();
                if (!wxApi.isWXAppInstalled()) {
                    UiTool.showToast(LoginActivity.this, "请安装微信客户端");
                    return;
                }
                //微信登录
                final SendAuth.Req req = new SendAuth.Req();
                req.scope = HttpApi.WEIXIN_SCOPE;
                req.state = HttpApi.WEIXIN_STATE;
                Logger.i("发送消息===" + wxApi.sendReq(req));
                Logger.i("微信登录");
                break;
            case R.id.btn_login:
                //未登录直接进入主页
                startActivity(new Intent(LoginActivity.this, HomeActivity.class));
                finish();
                break;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        JCVideoPlayer.releaseAllVideos();
    }
}
